package com.tasks.positions.domain;

/**
 * The instance of this class should be used as a complex key to guarantee the
 * uniqueness of each position.
 */
public final class PositionId {
	private final String accountNumber;

	private final String securityId;

	public PositionId(String accountNumber, String securityId) {
		this.accountNumber = accountNumber;
		this.securityId = securityId;
	}

	public String getAccountNumber() {
		return accountNumber;
	}

	public String getSecurityId() {
		return securityId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((accountNumber == null) ? 0 : accountNumber.hashCode());
		result = prime * result
				+ ((securityId == null) ? 0 : securityId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PositionId other = (PositionId) obj;
		if (accountNumber == null) {
			if (other.accountNumber != null)
				return false;
		} else if (!accountNumber.equals(other.accountNumber))
			return false;
		if (securityId == null) {
			if (other.securityId != null)
				return false;
		} else if (!securityId.equals(other.securityId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return accountNumber + "|" + securityId;
	}
}
